package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.service.ReportBookService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Version: V1.0
 */
@RestController
@RequestMapping("/reportBook")
public class ReportBookController {
    @Reference
    private ReportBookService reportBookService;

    @RequestMapping("/action")
    public Result action(@RequestBody List<Date> dateValue) {
        Map<String, Object> map = new HashMap<>();
        List<String> dates = new ArrayList<>();
        if (dateValue.size() == 0 || dateValue==null) {
            dates = reportBookService.findAllDate();
        } else {
            dates = reportBookService.findDate(dateValue);
        }
        List<Integer> bookAll = new ArrayList<>();
        List<Integer> bookOn = new ArrayList<>();
        if (dates != null && dates.size() > 0) {
            for (String date : dates) {
                Integer cc = reportBookService.findBookAllByDate(date);
                bookAll.add(cc);
                Integer bb = reportBookService.findBookOnByDate(date);
                bookOn.add(bb);
            }
        }
        map.put("dates", dates);
        map.put("bookAll", bookAll);
        map.put("bookOn", bookOn);
        return new Result(true, "上传预约,到诊图成功", map);
    }

}
